<?php
/**
* 
*/
class CreateMenuAction extends Action
{
	function index(){
		$this->display();
	}
	public function create(){
		$res = $this->docreate();
		if($res['errcode']==0){
			$this->show('创建菜单成功');
		}else{
			$this->show($res['errmsg']);
		}
	}
	function docreate(){
		$getToken = new getTokenAction();
		$access_token = $getToken->get();
		//dump($access_token);die;
		$url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token='.$access_token;
		//dump($url);die;   
		$jsonmenu = '{
      "button":[           
      {
            "name":"用户中心",
           "sub_button":[
           {
               "type":"view",
               "name":"首页",
               "url":"http://aaa.17wsx.com/index.php/Scan/home"
            },
            {
               "type":"view",
               "name":"绑定账号",
               "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9d8f3d6a105a7b28&redirect_uri=http%3A%2F%2Faaa.17wsx.com/index.php/GetUserinfo&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
            },
            {
               "type":"view",
               "name":"图书搜索",
               "url":"http://aaa.17wsx.com/index.php/Scan/index"
            },
            {
               "type":"view",
               "name":"借书记录",
               "url":"http://aaa.17wsx.com/index.php/Scan/lendlog"
            },
            {
               "type":"view",
               "name":"还书记录",
               "url":"http://aaa.17wsx.com/index.php/Scan/givelog"
            }]
       },
       {
           "name":"管理员操作",
           "sub_button":[
            {
              "type":"view",
               "name":"图书录入",
               "url":"http://aaa.17wsx.com/index.php/Bookent/index"
            },
            {
               "type":"view",
               "name":"借/还图书",
               "url":"http://aaa.17wsx.com/index.php/Bookent/lend"
            },
            {
                "type":"view",
                "name":"发送还书提醒",
                "url":"http://aaa.17wsx.com/index.php/Selfsend/index"
            }]
       

       }]
 }';
 $result = $this->https_request($url, $jsonmenu);
 $result =json_decode($result,true);
return $result;
	}
	public function https_request($url,$data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}
}

?>